package com.itheima.service.impl;

import com.itheima.dao.IStudentDao;
import com.itheima.domain.Student;
import com.itheima.factory.Factory;
import com.itheima.service.IStudentService;

import java.util.ArrayList;

public class StudentServiceImpl implements IStudentService {
    private IStudentDao studentDao=Factory.getStudentDao() ;

    @Override
    public void add(Student student) {
        studentDao.add(student);
    }

    @Override
    public void delete(String sid) {
        studentDao.delete(sid);
    }

    @Override
    public void update(String sid, Student student) {
        studentDao.update(sid, student);
    }

    @Override
    public ArrayList<Student> findAll() {
        return studentDao.findAll();
    }

    @Override
    public boolean isExist(String sid) {
        ArrayList<Student> list = studentDao.findAll();
        if (list == null || list.size() == 0) {
            return false;
        }
        for (int i = 0; i < list.size(); i++) {
            Student student = list.get(i);
            if (student.getSid().equals(sid)) {
                return true;
            }

        }

        return false;
    }
}
